/** ***********一些基本jqury validate验证*********** */
jQuery.extend(jQuery.validator.messages, {
    required: "不能为空",
    remote: "请修正该字段",
    email: "请输入正确格式的电子邮件",
    url: "请输入合法的网址",
    date: "请输入合法的日期",
    dateISO: "请输入合法的日期 (ISO).",
    number: "请输入合法的数字",
    digits: "只能输入整数",
    creditcard: "请输入合法的信用卡号",
    equalTo: "请再次输入相同的值",
    accept: "请输入拥有合法后缀名的字符串",
    maxlength: jQuery.validator.format("长度不能大于{0}"),
    minlength: jQuery.validator.format("长度不能小于 {0}"),
    rangelength: jQuery.validator.format("长度必须在{0}和{1}之间"),
    range: jQuery.validator.format("数值必须在 {0}和 {1} 之间"),
    max: jQuery.validator.format("不能大于 {0}"),
    min: jQuery.validator.format("不能小于 {0}")
});
$.validator.addMethod("isMobile", function (value, element, params) {
    return isMobile(value);
}, '手机号码格式不正确');
$.validator.addMethod("isPhone", function (value, element, params) {
    return isPhone(value);
}, '固定电话格式不正确');
$.validator.addMethod("isEmail", function (value, element, params) {
    return isEmail(value);
}, '邮箱格式不正确');
$.validator.addMethod("isIdCard", function (value, element, params) {
    return isIDCardNo(value);
}, '身份证号码格式不正确');
$.validator.addMethod("isValidBusCode", function (value, element, params) {
    return isValidBusCode(value);
}, '营业执行号格式不正确');
$.validator.addMethod("isChinese", function (value, element, params) {
    return isChinese(value);
}, '请输入中文');
jQuery.validator.addMethod("isLongDate", function (value, element) {
    var reg = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
    var r = value.match(reg);
    if (r == null)
        return false;
    r[2] = r[2] - 1;
    var d = new Date(r[1], r[2], r[3], r[4], r[5], r[6]);
    if (d.getFullYear() != r[1])
        return false;
    if (d.getMonth() != r[2])
        return false;
    if (d.getDate() != r[3])
        return false;
    if (d.getHours() != r[4])
        return false;
    if (d.getMinutes() != r[5])
        return false;
    if (d.getSeconds() != r[6])
        return false;
    return true;
}, "请输入正确的日期");
jQuery.validator.addMethod("isShortDate", function (value, element) {
    var reg = /^(\d{4})\-(\d{2})\-(\d{2})$/;
    var r = value.match(reg);
    if (r == null)
        return false;
    r[2] = r[2] - 1;
    var d = new Date(r[1], r[2], r[3]);
    if (d.getFullYear() != r[1])
        return false;
    if (d.getMonth() != r[2])
        return false;
    if (d.getDate() != r[3])
        return false;
    return true;
}, "请输入正确的日期");
//验证两次输入值是否不相同
jQuery.validator.addMethod("notEqualTo", function (value, element, param) {
    return value != $(param).val();
}, $.validator.format("两次输入不能相同!"));
function showBadParamSpan(data) {
    $.each(data, function (k, v) {
        if (k == 'province' || k == 'city' || k == 'area') {
            k = 'area';
        }
        var span = $("#" + k).parent().find('span:last');
        if (span && span.attr('for') == k) {
            span.html(v);
            span.show();
        } else {
            var ret = '<span for="' + k
					+ '" generated="true" class="warning" style="">' + v
					+ '</span>';
            $("#" + k).parent().append(ret);
            $("#" + k).parent().find('span:last').show();
        }
    });
}

